package com.example.p98;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author Lenovo
 */
public class NetworkInfo {
    public static void main(String[] args) {
        try{
            InetAddress localHost = InetAddress.getLocalHost();
            String hostName = localHost.getHostName();
            System.out.println("本机名称："+hostName);
            String hostAddress = localHost.getHostAddress();
            System.out.println("本机IP地址："+hostAddress);
        }
        catch (UnknownHostException e){
            System.out.println("无法获取本机IP地址及主机名:"+e.getMessage());
                    e.printStackTrace();
        }
    }
}
